#coding=utf-8

require "pathname"

module Aio::Module
	class InputStyle
		
		class ErrorModuleInput < StandardError
			def to_s; "请重载此方法"; end
		end

		# 重要！
		# 输入文件
		attr_accessor :input_file

		# 信息
		attr_accessor 	:input_info

		# 外加信息,用于针对特殊情况
		attr_accessor :ext_info

		def initialize(info={})
			@input_info = info.dup
			set_defaults()
		end

		def set_defaults
			self.input_info = {
				:author				=> nil,
				:description 	=> "No Input Description",
				# 产生文件的平台
				:platform			=> nil,
				:file_suffix	=> nil,
				:pass_file		=> nil,
				:license   		=> ::Aio::AIO_LICENSE,
			}.update(@input_info)

		end

		def type
			Aio::Module::InputStyle
		end

		# 保证输出的file为Pathname类
		def check_file(file)
			if file.class != Pathname
				case file.class
				when String
					file = Pathname.new(file)
				when File
					file = Pathname.new(file.path)
				end
			end
			file
		end

		# 请重载此方法
		def parse
			raise ErrorModuleInput.new			
		end

		# 检查是否符合文件后缀，符合返回真
		def file_suffix?(file)
			if self.file_suffix.match(file)
				return true
			end
			return false
		end

		# 检查是否符合pass_file， 符合返回真
		def pass_file?(file)
			self.pass_file.each do |pass|
				if pass.match(Aio::Base::Toolkit::String.safe(file))
					return true
				end
			end
			return false
		end

		def input_file
			@input_info[:input_file]
		end

		def input_file=(file)
			file = check_file(file)
			@input_info[:input_file] = file
		end

		def author;    		self.input_info[:author];    		end 
		def description;  self.input_info[:description];  end 
		def platform;  		self.input_info[:platform];  		end 
		def file_suffix;	self.input_info[:file_suffix];	end
		def license;   		self.input_info[:license];   		end 
		def pass_file;		self.input_info[:pass_file];		end


	end	# class
end	# module
